Strict Alternation Approach is the software mechanism implemented at user mode. It is a busy waiting solution which can be implemented only for two processes. In this approach, A turn variable is used which is actually a lock. This approach can only be used for only two processes. In general, let the two processes be P0 and P1. They share a variable called turn variable. The execution of the algorithm can be seen in following steps
Turn Box : Displays the value of the turn variable, indicating which process's turn it is to enter the critical section.
Process0 : Clicking this button will move process P0 forward.
Process1 : Clicking this button will move process P1 forward.
EndP0 : If P0 is in the critical section, clicking this button will end the process and return it to the non-critical section.
EndP1 : If P1 is in the critical section, clicking this button will end the process and return it to the non-critical section.
Reset : Reloads the page.
Press Process0, and since the turn is for P0, it will move P0 into the critical section.
If P1 is ready to enter the critical section, press Process1. This will check if it is P1's turn. If not, P1 will enter a while loop until P0 completes its execution.
Once the execution of P0 is complete, press EndP0 to move it to the non-critical section and change the turn variable to P1.
Since the critical section is empty and it is P1's turn, with P1 ready in the while loop, press Process1 to move P1 into the critical section.
If P0 is ready to be executed again, press Process0. However, if the critical section is not empty and it is P1's turn, P0 will enter the while loop.
Once P1 completes its execution, press EndP1 to move it to the non-critical section. Then, press Process0 to move P0 into the critical section, as the turn variable indicates P0 and the critical section is empty.
If the turn variable is set to P0 and you press Process1, an alert message will indicate that "it is process 0's turn." This condition applies when both processes are in the non-critical section.
If the turn variable is set to P1 and you press Process0, an alert message will indicate that "it is process 1's turn." This condition applies when both processes are in the non-critical section.
1.Mutual Exclusion
The strict alternation approach ensures mutual exclusion in every scenario, but it is applicable only for two processes. The pseudocode differs for each process. A process will enter the critical section only when the turn variable matches its Process ID. Consequently, no process can enter the critical section unless it is their designated turn.
2.Progress
Progress is not guaranteed in this mechanism. If P0 does not wish to enter the critical section during its turn, P1 may be blocked indefinitely. P1 must wait for its turn because the turn variable will remain 0 until P0 changes it to 1.
3.Portability
The solution provides portability. It is a pure software mechanism implemented at user mode and doesn't need any special instruction from the Operating System.